import { BasicColumn, FormSchema } from '/@/components/Table';
import { bindMapFormSchema } from '/@/utils/common/compUtils';
import { reactive } from 'vue';
import { getFileSize } from '/@/utils/index';
import { isNumber } from '/@/utils/is';

export const fileFlagOptions = reactive([
  {
    fileId: '0',
    fileName: '我的文件',
    icon: 'ant-design:paper-clip-outlined',
    style: 'font-size: 16px; color: rgb(0, 145, 234); display: inline-flex; transform: rotate(-44deg)',
    isShowSetting: true,
    isSelected: false,
    isHover: false,
    dropdownVisible: false,
  },
  {
    fileId: '1',
    fileName: '最近使用',
    icon: 'ant-design:field-time-outlined',
    style: 'font-size: 16px; color: rgb(0, 188, 212); display: inline-flex',
    isShowSetting: false,
    isSelected: false,
    isHover: false,
    dropdownVisible: false,
  },
  {
    fileId: '2',
    fileName: '星标文件',
    icon: 'ant-design:star-outlined',
    style: 'font-size: 16px; color: rgb(255, 152, 0); display: inline-flex',
    isShowSetting: false,
    isSelected: false,
    isHover: false,
    dropdownVisible: false,
  },
]);

//共享目录操作菜单
export const myFilesMenu = [
  {
    value: 'log',
    label: '文件夹日志',
    icon: 'ant-design:file-text-outlined',
  },
  {
    value: 'recycle',
    label: '回收站',
    icon: 'ant-design:rest-twotone',
  },
];

// 文件归属类型选项
export const fileOwnershipTypeOptions = [
  {
    value: '0',
    label: '全部共享文件',
  },
  {
    value: '1',
    label: '我拥有的',
  },
  {
    value: '2',
    label: '我加入的',
  },
];

//共享目录操作菜单
export const folderOwnershipMenu = function (record) {
  const data: any = [];
  data.push({
    value: 'star',
    label: record.isStar == '1' ? '取消标星' : '标星',
    icon: 'ant-design:star-filled',
  });
  data.push({
    value: 'team',
    label: '共享设置',
    icon: 'ant-design:team-outlined',
  });
  data.push({
    value: 'log',
    label: '文件夹日志',
    icon: 'ant-design:file-text-outlined',
  });
  data.push({
    value: 'recycle',
    label: '回收站',
    icon: 'ant-design:rest-twotone',
  });
  if (record.authority == 'owner' || record.authority == 'admin') {
    data.push({
      value: 'del',
      label: '删除文件夹',
      icon: 'ant-design:delete-outlined',
    });
  } else {
    data.push({
      value: 'exit',
      label: '退出文件夹',
      icon: 'ant-design:export-outlined',
    });
  }

  return data;
};

//用户权限
export const folderPermissionOptions = [
  {
    value: 'admin',
    label: '管理员',
  },
  {
    value: 'editable',
    label: '可编辑',
  },
  {
    value: 'readonly',
    label: '只读',
  },
];

//文件添加操作菜单
export const fileCreateMenu = [
  {
    value: 'uploadLocal',
    label: '上传本地文件',
  },
  {
    value: 'createLinkFile',
    label: '添加链接文件',
  },
  {
    value: 'createFolder',
    label: '新建文件夹',
  },
];

//文件添加操作菜单
export const fileMenu = function (record) {
  const data: any = [];
  if (record.isDel == '1') {
    data.push({
      value: 'rollback',
      label: '还原',
      icon: 'ant-design:rollback-outlined',
    });
    data.push({
      value: 'cdel',
      label: '彻底删除',
      icon: 'ant-design:delete-filled',
    });
  } else {
    if (record.isFolder == '0') {
      if (record.fileType == 'other') {
        data.push({
          value: 'edit',
          label: '编辑',
          icon: 'ant-design:edit-outlined',
        });
      }
      data.push({
        value: 'star',
        label: record.isStar == '0' ? '标星' : '取消标星',
        icon: 'ant-design:star-outlined',
      });
      data.push({
        value: 'divider',
        label: '',
        icon: '',
      });
    }
    data.push({
      value: 'rename',
      label: '重命名',
      icon: 'ant-design:edit-outlined',
    });
    // if (record.isFolder == '0' && record.fileType != 'other') {
    //   data.push({
    //     value: 'upload',
    //     label: '上传新版本',
    //     icon: 'ant-design:cloud-sync-outlined',
    //   });
    // }
    data.push({
      value: 'swap',
      label: '移动到...',
      icon: 'ant-design:swap-outlined',
    });
    data.push({
      value: 'copy',
      label: '复制到...',
      icon: 'ant-design:copy-outlined',
    });
    data.push({
      value: 'del',
      label: '删除',
      icon: 'ant-design:delete-outlined',
    });
    data.push({
      value: 'setting',
      label: '属性',
      icon: 'ant-design:info-circle-filled',
    });
  }
  return data;
};

/**
 * 获得文件类型对应ICON
 */
export const getFileTypeIcon = function (fileName, fileType) {
  if (fileType == 'folder') {
    return {
      useImage: false,
      image: '',
      icon: 'ant-design:folder-open-outlined',
      style: 'font-size: 16px;color: rgb(253, 202, 7);display: inline-flex;',
    };
  } else if (fileType == 'excel') {
    return {
      useImage: false,
      image: '',
      icon: 'ant-design:file-excel-outlined',
      style: 'font-size: 16px;color: rgb(98, 187, 55);display: inline-flex;',
    };
  } else if (fileType == 'doc') {
    return {
      useImage: false,
      image: '',
      icon: 'ant-design:file-word-outlined',
      style: 'font-size: 16px;color: rgb(59, 100, 252);display: inline-flex;',
    };
  } else if (fileType == 'pp') {
    return {
      useImage: false,
      image: '',
      icon: 'ant-design:file-ppt-outlined',
      style: 'font-size: 16px;color: rgb(223，64，35);display: inline-flex;',
    };
  } else if (fileType == 'image') {
    return {
      useImage: false,
      image: '',
      icon: 'ant-design:file-image-outlined',
      style: 'font-size: 16px;color: rgb(255, 87, 34);display: inline-flex;',
    };
  } else if (fileType == 'zip') {
    return {
      useImage: false,
      image: '',
      icon: 'ant-design:file-zip-outlined',
      style: 'font-size: 16px;color: rgb(27，149，60);display: inline-flex;',
    };
  } else if (fileType == 'video') {
    return {
      useImage: false,
      image: '',
      icon: 'ant-design:video-camera-outlined',
      style: 'font-size: 16px;color: rgb(98, 187, 55);display: inline-flex;',
    };
  } else if (fileType == 'text') {
    return {
      useImage: false,
      image: '',
      icon: 'ant-design:file-text-outlined',
      style: 'font-size: 16px;color: rgb(41, 211, 178);display: inline-flex;',
    };
  } else if (fileType == 'other') {
    const index = fileName.lastIndexOf('.');
    if (index >= 0) {
      const suffix = fileName.substring(index + 1);
      if (suffix == 'url') {
        return {
          useImage: false,
          image: '',
          icon: 'ant-design:link',
          style: 'font-size: 16px;color: rgb(98, 187, 55);display: inline-flex;',
        };
      }
    }
  }
  return {
    useImage: false,
    image: '',
    icon: 'ant-design:file-unknown',
    style: 'font-size: 16px;color: rgb(98, 187, 55);display: inline-flex;',
  };
};

export const columns: BasicColumn[] = [
  {
    //title: '文件名称',
    dataIndex: 'fileName',
    width: 500,
    edit: true,
    editComponentProps: {
      prefix: '$',
    },
    ellipsis: true,
    align: 'left',
    slots: { title: 'customTitle' },
    slotsBak: { customRender: 'fileName' },
  },
  {
    title: '创建者',
    dataIndex: 'createByName',
    width: 200,
    align: 'left',
  },
  {
    title: '修改时间',
    dataIndex: 'updateTime',
    width: 200,
    align: 'left',
    customRender: ({ text, record }) => {
      if (record.isFolder == '0') {
        return text;
      }
      return '';
    },
  },
  {
    title: '文件大小',
    dataIndex: 'fileSize',
    align: 'left',
    customRender: ({ text }) => {
      let val = text;
      if (val && isNumber(val)) {
        val = getFileSize(val);
      }
      if (val == 0) {
        return '-';
      } else {
        return val;
      }
    },
  },
];

const mapFormSchema = bindMapFormSchema(
  {
    col_span_one: {
      colProps: {
        xs: 24,
        sm: 12,
      },
      itemProps: {
        labelCol: { xs: 24, sm: 5 },
        wrapperCol: { xs: 24, sm: 18 },
        colon: true,
      },
      style: { width: '100%' },
    },
    col_span_two: {
      colProps: {
        xs: 24,
        sm: 24,
      },
      itemProps: {
        labelCol: { xs: 18, sm: 3 },
        wrapperCol: { xs: 24, sm: 20 },
        colon: true,
      },
      style: { width: '100%' },
    },
  },
  'col_span_one'
);

export const formSchema: FormSchema[] = [
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
  {
    field: 'name',
    component: 'Input',
    label: '文件夹名称',
    slot: 'folderName',
    itemProps: {
      labelCol: { class: 'folder-name-text' },
    },
  },
  mapFormSchema(
    {
      field: 'name',
      component: 'Input',
      label: '',
      slot: 'folderName',
    },
    'col_span_two'
  ),
  mapFormSchema(
    {
      field: 'name',
      component: 'Input',
      label: '',
      slot: 'folderName',
    },
    'col_span_two'
  ),
];
